#include "photontracer.hpp"


Photontracer::Photontracer(Scene* _scene,const unsigned short _depth) : scene(_scene) , depth(_depth) 
{ }

Photontracer::~Photontracer(void) {
	delete scene;
}

void Photontracer::trace(void) {
	Photon_Map photon_map;
	
	unsigned int hit = 0;
	unsigned int all = 0;
	for(int l=0;l<scene->getLightesEnd();l++) { /*For each light, calculate specular and diffuse */
		Light* light = scene->get_light(0);
		Vector point;
		
		Ray ray(light->get_origin(),Vector(0.0,0.0,0.0));
		
		
		
		for(double teta1 = -M_PI/2.0; teta1 <= M_PI/2.0; teta1 = teta1 + 0.01) {
			for(double teta2 = 0;teta2 <= 2*M_PI;teta2  = teta2 + 0.01) {
					ray.set_direction(Vector(cos(teta1)*cos(teta2),
											cos(teta1)*sin(teta2),
											sin(teta1)).normalize()
									);
					int obj = scene->nearest_object(point,ray);
					all++;
					if(obj != -1) { /* -1 means: "found something" */
						Photon* photon = new Photon(Color(),point,Vector());
						photon_map.insert(photon);
						hit++;
					}
			}

		}
		
		Kd_Tree* kd_tree = photon_map.construct_kd_tree_rec();
		//kd_tree->root->pre_order();
	}
	
}

